#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    // QT 为了保证程序的流畅性，默认情况下不会对鼠标移动进行追踪，鼠标移动时不会调用mouseMoveEvent
    // 除非显式的告诉 QT 要追踪鼠标位置
    this->setMouseTracking(true);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::mouseMoveEvent(QMouseEvent *event)
{
    qDebug() << event->x() << ", " << event->y();
}

void Widget::wheelEvent(QWheelEvent *event)
{
    // qDebug() << event->delta();
    QFont font = ui->label->font();
    if(event->delta() > 0)
    {
        font.setPointSize(font.pointSize() + 1);
        ui->label->setFont(font);
    }
    else if(event->delta() < 0)
    {
        font.setPointSize(font.pointSize() - 1);
        ui->label->setFont(font);
    }
}
